﻿@model Dqaqs.Data.Schema

@{
    ViewBag.Title = "Upload Data";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Upload Data</h2>

<script src="@Url.Content("~/Scripts/jsrender.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.forms.js")" type="text/javascript"></script>

@using (Html.BeginForm("UploadData", "DataSource", FormMethod.Post, new { id = "mainForm", enctype="multipart/form-data" }))
{
    <fieldset>
        <legend>Data Source</legend>

        <div class="editor-label">
            @Html.Label((string)ViewBag.Title)
        </div>

        @Html.Label("Following files were uploaded successfully:")
        <table border="1">
        <thead>
        <tr>
        <td width="150">Table</td>
        <td width="150">File</td>
        </tr>
        </thead>
        @if (ViewBag.Uploaded != null)
        {
            var files = (Tuple<string, string>[])ViewBag.Uploaded;
            foreach (var file in files)
            {
                <tr>
                <td>
                @file.Item1
                </td>
                <td>
                @file.Item2
                </td>
                </tr>
            }
        }
        </table>

            @Html.Hidden("id", (int)ViewBag.Id, new { id = "id" })
            @Html.Hidden("projectId", (Guid)ViewBag.ProjectId, new { id = "projectId" })
        <div class="editor-label">
            @Html.Label("Tables")
        </div>
        @if (Model != null && Model.Tables != null)
        {
            foreach (var table in Model.Tables)
            {
                 <div class="editor-label">
                    <h3>@Html.Label(table.Name)</h3>
                    <p>Uploaded file <B>must</B> follow the following format:<br />
                    @{var first = true;}
                    @foreach (var col in table.Columns)
                    {
                        WriteLiteral((first ? "" : ", ") + col.Name);
                        WriteLiteral(String.Format(" ( {0} ) ", col.Type));
                        first = false;
                    }
                    </p>
                    <input name="upload-@table.Name" type="file" />
                 </div>
            }
        }
        
        <p>
            <input type="submit" value="Submit" />
        </p>
    </fieldset>
}

<script>
    $(function () {
    });


</script>